//package edu.oregonstate.eecs.cs331.assn1;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.ArrayList;
import javax.swing.JComponent;

//fake comment
/**
 * This class is responsible for representing a cell in the maze.  It stores
 * data about how it is drawn, as well as state data representing whether or
 * not the cell has been visited or used in a valid solution.
 */
public class MazeCell extends JComponent {

	// Dimensions of the cell onscreen
	public static final int CELL_W = 15;
	public static final int CELL_H = 15;

	// Public static constants for the directions
	public static final int NORTH = 0;
	public static final int EAST = 1;
	public static final int SOUTH = 2;
	public static final int WEST = 3;
	
	// Public static constant for the number of neighbors
	private static final int NUM_CELL_NEIGHBORS = 4;
	
	// represents whether or not the cell is a special one (start/finish)
	private boolean finish;
	private boolean start;
	
	// represents state of the search and its use of this cell
	private boolean visited;
	private boolean used;
	
	// x-y coordinates of the cell
	private int x;
	private int y;
	
	// References to the neighbors. The neighbor reference is set to null if you
	// can't go in that direction.
	private MazeCell northNeighbor;
	private MazeCell eastNeighbor;
	private MazeCell southNeighbor;
	private MazeCell westNeighbor;
	
	public MazeCell parent;
	
	
	// This int encodes the location and number of walls that the cell has
	// protecting it from the outside cells.
	private int type;

	// Leave the line below in your code. You won't need to know what it is for
	// this course.
	private static final long serialVersionUID = 1L;
	
	/**
	 * Constructor which initializes the values of the cell.  Takes
	 * 2 arguments representing the index of the cell on the grid
	 * @param x x-Index on the grid
	 * @param y y-Index on the grid
	 */
	public MazeCell(int x, int y) {
		this.x = x;
		this.y = y;
		this.northNeighbor = null;
		this.eastNeighbor = null;
		this.southNeighbor = null;
		this.westNeighbor = null;
		
		type = 0;
		start = false;
		finish = false;
		used = false;
		
		visited = false;
		setPreferredSize(new Dimension(MazeCell.CELL_W, MazeCell.CELL_H));
	}
	
	/**
	 * This function is responsible for drawing the cell.  It
	 * responds to state data regarding whether or not a valid
	 * solution uses the cell, whether or not it was visited along
	 * the way, and whether or not it is the start/finish node.
	 */
	public void paintComponent(Graphics g) {
		if(visited && used)
			g.setColor(Color.ORANGE);
		else if(visited)
			g.setColor(Color.BLUE);
		else
			g.setColor(Color.WHITE);
		g.fillRect(1, 1, CELL_W - 2, CELL_H - 2);
		
		if(start)
		{
			g.setColor(Color.GREEN);
			g.fillArc(1, 1, CELL_W - 1, CELL_H - 1, 0, 360);
		} else if(finish)
		{
			g.setColor(Color.RED);
			g.fillArc(1, 1, CELL_W - 1, CELL_H - 1, 0, 360);
		}
		
		g.setColor(Color.BLACK);
        if ((type & 1) != 0) g.drawLine(1, CELL_H-1, CELL_W-1, CELL_H-1);
        if ((type & 2) != 0) g.drawLine(CELL_W-1, 1, CELL_W-1, CELL_H-1);
        if ((type & 4) != 0) g.drawLine(1, 1, CELL_W-1, 1);
        if ((type & 8) != 0) g.drawLine(1, 1, 1, CELL_H-1);
	}


	/*
	 * Various setters/getters. Fairly self-explanatory.
	 */
	public MazeCell getNorthNeighbor() 	{return this.northNeighbor;}
	public MazeCell getEastNeighbor() 	{return this.eastNeighbor;}
	public MazeCell getSouthNeighbor() 	{return this.southNeighbor;}
	public MazeCell getWestNeighbor() 	{return this.westNeighbor;}
	
	public void setNorthNeighbor(MazeCell n)		{this.northNeighbor = n;}
	public void setEastNeighbor(MazeCell n)			{this.eastNeighbor = n;}
	public void setSouthNeighbor(MazeCell n)		{this.southNeighbor = n;}
	public void setWestNeighbor(MazeCell n)			{this.westNeighbor = n;}
	
	public int getType() 				{return type;}
	public void setType(int t) 			{type = t;}
	
	public boolean isFinish() 			{return finish;}
	public void setFinish() 			{finish = true;}
	
	public boolean isStart() 			{return start;}
	public void setStart() 				{start = true;}
	
	public boolean isVisited() 			{return visited;}
	public void setVisited(boolean v) 	{visited = v;}
	
	public void setUsed(boolean u) 		{used = u;}
}